/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ipostservices.model.dao;

import ipostservices.model.bean.Project;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author sixviv
 */
public class ProjectDAO extends GeneralDAO<Project>{

    public List<Project> getProys(int idUser){
        List<Project> result=new ArrayList();
        session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(Project.class);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.setFetchMode("user", FetchMode.JOIN);
        criteria.setFetchMode("postits", FetchMode.JOIN); 
        criteria.setFetchMode("postits.user", FetchMode.JOIN);
        criteria.setFetchMode("users", FetchMode.JOIN);
        criteria.add(Restrictions.eq("user.iduser", idUser));
        result = criteria.list();
        session.close();
        return result;
    }

    public Project getProysById (int idProy){
        session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(Project.class);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.setFetchMode("user", FetchMode.JOIN);
        criteria.setFetchMode("postits", FetchMode.JOIN); 
        criteria.setFetchMode("postits.user", FetchMode.JOIN);
        criteria.setFetchMode("users", FetchMode.JOIN);
        criteria.add(Restrictions.eq("idproject", idProy));
        Project project = (Project)criteria.uniqueResult();
        session.close();
        return project;
    }

}
